FROM nvcr.io/nvidia/l4t-jetpack:r35.4.1

ARG HTTP_PROXY=socks5://127.0.1:7897
ARG HTTPS_PROXY=socks5://127.0.1:7897
ARG MINICONDA_INSTALL_URL=https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh
ARG MINICONDA_INSTALL_PATH=/home/miniconda3
WORKDIR /home
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak && \
    sed -i 's|http://ports.ubuntu.com/ubuntu-ports/|https://repo.huaweicloud.com/ubuntu-ports/|g' /etc/apt/sources.list && \
    sed -i 's|http://archive.ubuntu.com/ubuntu|https://repo.huaweicloud.com/ubuntu-ports|g' /etc/apt/sources.list && \
    sed -i 's|http://security.ubuntu.com/ubuntu/|https://repo.huaweicloud.com/ubuntu-ports/|g' /etc/apt/sources.list && \
    apt update -y && \
    apt install -y libeigen3-dev libopenni2-dev lsb-release curl git python3-pip && \
    # install miniconda
    mkdir -p /home/download/ && cd /home/download/ \
    curl -x $HTTP_PROXY -o Miniconda3-latest-Linux-aarch64.sh $MINICONDA_INSTALL_URL && \
    chmod +x Miniconda3-latest-Linux-aarch64.sh && \
    ./Miniconda3-latest-Linux-aarch64.sh -b -p $MINICONDA_INSTALL_PATH && \
    $MINICONDA_INSTALL_PATH/bin/conda init bash && \
    conda config --set auto_activate_base false && \
    . ~/.bashrc && \
    rm -rf /home/download/Miniconda3-latest-Linux-aarch64.sh && \
    # config conda download source
    echo "channels:" > ~/.condarc && \
    echo "  - defaults" >> ~/.condarc && \
    echo "show_channel_urls: true" >> ~/.condarc && \
    echo "default_channels:" >> ~/.condarc && \
    echo "  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main" >> ~/.condarc && \
    echo "  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r" >> ~/.condarc && \
    echo "  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2" >> ~/.condarc && \
    echo "custom_channels:" >> ~/.condarc && \
    echo "  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud" >> ~/.condarc && \
    echo "  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud" >> ~/.condarc && \
    echo "  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud" >> ~/.condarc && \
    echo "  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud" >> ~/.condarc && \
    echo "  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud" >> ~/.condarc && \
    echo "  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud" >> ~/.condarc && \
    conda clean --all --yes && \
    # git clone 
    git config --global http.proxy socks5://127.0.0.1:7897 && \
    git config --global https.proxy socks5://127.0.0.1:7897 && \
    cd /home && \
    git clone https://github.com/huggingface/lerobot.git && \
    cd lerobot && \
    conda create -y -n smolvla python=3.10 && \
    conda activate smolvla && \
    conda install ffmpeg -c conda-forge -y && \
    pip install -e . && \
    pip install -e ".[smolvla]" && \
    apt clean && rm -rf /var/lib/apt/lists/* && \
    rm -rf ~/.cache/pip && \
    conda clean --all -f -y 